<template>
  <div>
    <van-tabs v-model="active" title-active-color="#1869FF" title-inactive-color="#1D2129" @click="onClick" sticky>
      <van-tab :title="item.title" v-for="(item, index) in tabList" :key="index">
        <van-list
          :loading="loading"
          :finished="finished"
          loading-text="上划加载更多"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <van-cell v-for="(item, i) in list" :key="i" :title="item.title">
            <div class="card-item" @click="goDetail(item.weMomentsTaskId)">
              <!-- 任务名称 -->
              <div class="task">
                <div class="task-name">{{ item.name }}</div>
                <div class="task-button " :class="item.executeStatus ? 'task-button-blue' : 'task-button-red'">
                  {{ item.executeStatus ? '已执行' : '未执行' }}
                </div>
              </div>
              <div class="task2">
                <div class="task-create">
                  <div class="task-create-name">{{ item.createBy }}</div>
                  创建
                </div>
                <van-count-down :time="dealTime(item.executeEndTime)" v-if="query.status === 2">
                  <template #default="timeData">
                    <span class="block">{{ timeData.days }}</span>
                    <span class="colon">天</span>
                    <span class="block">{{ timeData.hours }}</span>
                    <span class="colon">时</span>
                    <span class="block">{{ timeData.minutes }}</span>
                    <span class="colon">分</span>
                  </template>
                </van-count-down>
              </div>
              <div class="task-time" v-if="query.status === 3">{{ item.executeTime }}--{{ item.executeEndTime }}</div>
              <van-divider />
              <!-- 引导语 -->
              <div class="guide">
                <span>{{ item.content }}</span>
              </div>
              <!-- 文件展示 -->
              <ShowFile :materialList="item.materialList" v-if="item.materialList && item.materialList.length" />
              <!-- <van-divider /> -->
              <!-- 目标类型 -->
              <!-- <div class="model-type">
                <div class="type-top">
                  <span>发送目标客户类型</span>
                  <span>{{ item.customerNum }}名客户</span>
                </div>
                <div class="type-tag" v-if="item.customerTags && item.customerTags.length">
                  <div class="type-tag-item" v-for="(item1, i) in item.customerTags" :key="i">
                    {{ item1 }}
                  </div>
                </div>
                <div class="all-curstom" v-else>全部客户</div>
              </div> -->
              <!-- <div class="send-button" v-if="item.executeStatus === 0 && query.status === 2">
                <div class="button-send" @click.stop="goSend(item)"></div>
              </div> -->
            </div>
          </van-cell>
        </van-list>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { momentsList } from '@/api/friends'
import ShowFile from './components/ShowFile.vue'
export default {
  components: {
    ShowFile,
  },
  data() {
    return {
      active: 0,
      tabList: [{ title: '进行中' }, { title: '已结束' }],
      // time: 0,
      list: [],
      finished: false,
      loading: false,
      query: {
        pageNum: 1,
        pageSize: 10,
        status: 2,
      },
      total: 0,
    }
  },
  mounted() {
    this.getList(true)
  },
  methods: {
    onClick(a, b) {
      if (a === 0) {
        this.query.status = 2
      } else {
        this.query.status = 3
      }
      this.finished = false
      this.total = 0
      this.list = []
      this.query.pageNum = 1
      this.getList(true)
    },
    onLoad() {
      if (this.total > this.list.length) {
        this.query.pageNum++
        this.getList()
      } else {
        this.finished = true
      }
    },
    // 获取列表
    getList(falge) {
      this.loading = true
      momentsList(this.query)
        .then((res) => {
          // res.rows = [
          //   {
          //     weMomentsTaskId: '1673601199295913984',
          //     momentsId: null,
          //     name: '99',
          //     createBy: 'admin',
          //     executeTime: null,
          //     executeEndTime: '2023-06-28 00:00',
          //     content: null,
          //     customerTags: null,
          //     customerNum: 0,
          //     executeStatus: 0,
          //     materialList: [
          //       {
          //         searchValue: null,
          //         createBy: 'admin',
          //         createById: '1',
          //         createTime: '2023-06-26 16:20:31',
          //         updateBy: 'admin',
          //         updateById: '1',
          //         updateTime: '2023-06-26 17:04:14',
          //         remark: null,
          //         params: {},
          //         id: '1673244838125940737',
          //         categoryId: '1',
          //         fileName: null,
          //         moduleType: 1,
          //         materialUrl: null,
          //         materialName: '66',
          //         content: '<p>66</p>',
          //         digest: null,
          //         coverUrl:
          //           'https://dev.linkwechat.net/fileUpload/8e58d4c9-aae2-4c38-b622-dad6cf46788a.png',
          //         audioTime: '0',
          //         backgroundImgUrl: null,
          //         type: null,
          //         width: 80,
          //         height: 80,
          //         mediaType: '12',
          //         otherField: null,
          //         materialStatus: 0,
          //         frontOrder: null,
          //         delFlag: 0,
          //         linkUrl: null,
          //         isCheck: false,
          //         posterSubassembly: null,
          //         posterQrType: null,
          //         pixelSize: '6400',
          //         memorySize: '1452',
          //         weMaterialImgAoList: null,
          //       },
          //     ],
          //   },
          //   {
          //     weMomentsTaskId: '1673600967120216064',
          //     momentsId: null,
          //     name: '88',
          //     createBy: 'admin',
          //     executeTime: null,
          //     executeEndTime: '2023-07-01 00:00',
          //     content: null,
          //     customerTags: null,
          //     customerNum: 0,
          //     executeStatus: 0,
          //     materialList: [
          //       {
          //         searchValue: null,
          //         createBy: 'admin',
          //         createById: '1',
          //         createTime: '2023-06-26 16:04:31',
          //         updateBy: 'admin',
          //         updateById: '1',
          //         updateTime: '2023-06-26 17:05:06',
          //         remark: null,
          //         params: {},
          //         id: '1673240810063179778',
          //         categoryId: '1',
          //         fileName: null,
          //         moduleType: 1,
          //         materialUrl: 'http://ww.baidu.com',
          //         materialName: '33',
          //         content: null,
          //         digest: null,
          //         coverUrl:
          //           'https://dev.linkwechat.net/fileUpload/d31601de-879a-41c8-9ce4-9d2f9a4ad847.png',
          //         audioTime: '0',
          //         backgroundImgUrl: null,
          //         type: null,
          //         width: 80,
          //         height: 80,
          //         mediaType: '9',
          //         otherField: null,
          //         materialStatus: 0,
          //         frontOrder: null,
          //         delFlag: 0,
          //         linkUrl: null,
          //         isCheck: false,
          //         posterSubassembly: null,
          //         posterQrType: null,
          //         pixelSize: '6400',
          //         memorySize: '1533',
          //         weMaterialImgAoList: null,
          //       },
          //     ],
          //   },
          //   {
          //     weMomentsTaskId: '1673600785376829440',
          //     momentsId: null,
          //     name: '77',
          //     createBy: 'admin',
          //     executeTime: null,
          //     executeEndTime: '2023-06-30 00:00',
          //     content: null,
          //     customerTags: null,
          //     customerNum: 0,
          //     executeStatus: 0,
          //     materialList: [
          //       {
          //         searchValue: null,
          //         createBy: 'admin',
          //         createById: '1',
          //         createTime: '2023-06-26 17:48:03',
          //         updateBy: 'admin',
          //         updateById: '1',
          //         updateTime: '2023-06-26 17:48:03',
          //         remark: null,
          //         params: {},
          //         id: '1673266863921999874',
          //         categoryId: '1',
          //         fileName: null,
          //         moduleType: 1,
          //         materialUrl:
          //           'https://dev.linkwechat.net/fileUpload/3ba1d8d4-75b4-4285-9896-a8e76b068254.png',
          //         materialName: 'ARTICAL.png',
          //         content: null,
          //         digest: null,
          //         coverUrl: null,
          //         audioTime: '0',
          //         backgroundImgUrl: null,
          //         type: null,
          //         width: 80,
          //         height: 80,
          //         mediaType: '0',
          //         otherField: null,
          //         materialStatus: 0,
          //         frontOrder: null,
          //         delFlag: 0,
          //         linkUrl: null,
          //         isCheck: false,
          //         posterSubassembly: null,
          //         posterQrType: null,
          //         pixelSize: '6400',
          //         memorySize: '1533',
          //         weMaterialImgAoList: null,
          //       },
          //       {
          //         searchValue: null,
          //         createBy: 'admin',
          //         createById: '1',
          //         createTime: '2023-06-26 17:48:03',
          //         updateBy: 'admin',
          //         updateById: '1',
          //         updateTime: '2023-06-26 17:48:03',
          //         remark: null,
          //         params: {},
          //         id: '1673266864123326465',
          //         categoryId: '1',
          //         fileName: null,
          //         moduleType: 1,
          //         materialUrl:
          //           'https://dev.linkwechat.net/fileUpload/7c5080e9-da20-47e1-8cee-c77ff9e7d6f0.png',
          //         materialName: 'favicon.png',
          //         content: null,
          //         digest: null,
          //         coverUrl: null,
          //         audioTime: '0',
          //         backgroundImgUrl: null,
          //         type: null,
          //         width: 379,
          //         height: 379,
          //         mediaType: '0',
          //         otherField: null,
          //         materialStatus: 0,
          //         frontOrder: null,
          //         delFlag: 0,
          //         linkUrl: null,
          //         isCheck: false,
          //         posterSubassembly: null,
          //         posterQrType: null,
          //         pixelSize: '143641',
          //         memorySize: '7359',
          //         weMaterialImgAoList: null,
          //       },
          //       {
          //         searchValue: null,
          //         createBy: 'admin',
          //         createById: '1',
          //         createTime: '2023-06-26 18:15:57',
          //         updateBy: 'admin',
          //         updateById: '1',
          //         updateTime: '2023-06-26 18:15:57',
          //         remark: null,
          //         params: {},
          //         id: '1673273884138319874',
          //         categoryId: '1',
          //         fileName: null,
          //         moduleType: 1,
          //         materialUrl:
          //           'https://dev.linkwechat.net/fileUpload/e5de9431-8a13-41d3-8013-f54d9127636f.png',
          //         materialName: 'ARTICAL.png',
          //         content: null,
          //         digest: null,
          //         coverUrl: null,
          //         audioTime: '0',
          //         backgroundImgUrl: null,
          //         type: null,
          //         width: 80,
          //         height: 80,
          //         mediaType: '0',
          //         otherField: null,
          //         materialStatus: 0,
          //         frontOrder: null,
          //         delFlag: 0,
          //         linkUrl: null,
          //         isCheck: false,
          //         posterSubassembly: null,
          //         posterQrType: null,
          //         pixelSize: '6400',
          //         memorySize: '1533',
          //         weMaterialImgAoList: null,
          //       },
          //       {
          //         searchValue: null,
          //         createBy: 'admin',
          //         createById: '1',
          //         createTime: '2023-06-26 18:15:57',
          //         updateBy: 'admin',
          //         updateById: '1',
          //         updateTime: '2023-06-26 18:15:57',
          //         remark: null,
          //         params: {},
          //         id: '1673273884415143938',
          //         categoryId: '1',
          //         fileName: null,
          //         moduleType: 1,
          //         materialUrl:
          //           'https://dev.linkwechat.net/fileUpload/6b5af22d-518b-472b-885f-4b16a758a2eb.png',
          //         materialName: 'favicon.png',
          //         content: null,
          //         digest: null,
          //         coverUrl: null,
          //         audioTime: '0',
          //         backgroundImgUrl: null,
          //         type: null,
          //         width: 379,
          //         height: 379,
          //         mediaType: '0',
          //         otherField: null,
          //         materialStatus: 0,
          //         frontOrder: null,
          //         delFlag: 0,
          //         linkUrl: null,
          //         isCheck: false,
          //         posterSubassembly: null,
          //         posterQrType: null,
          //         pixelSize: '143641',
          //         memorySize: '7359',
          //         weMaterialImgAoList: null,
          //       },
          //     ],
          //   },
          // ]
          // res.total = 3

          if (res.code === 200) {
            this.total = +res.total
            if (falge) {
              this.list = res.rows
            } else {
              this.list.push(...res.rows)
            }
            this.loading = false
            this.finished = false
          }
        })
        .catch()
    },
    goDetail(id) {
      this.$router.push({ name: 'friendsDetail', query: { id } })
    },
    // 将日期转为毫秒
    dealTime(time) {
      let nowTime = +new Date()
      let numTime = +new Date(time)
      if (numTime > nowTime) {
        return numTime - nowTime
      } else {
        return 0
      }
    },
  },
}
</script>

<style lang="less" scoped>
.send-button {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 16px;
}
.button-send {
  width: 92.7%;
  height: 44px;
  background: linear-gradient(90deg, #1869ff 0%, #5e8fff 100%);
  border-radius: 16px 16px 16px 16px;
  opacity: 1;
  line-height: 44px;
  text-align: center;
  font-size: 18px;
  font-family: Source Han Sans CN-Medium, Source Han Sans CN;
  font-weight: 500;
  color: #ffffff;
}
/deep/ .van-cell {
  margin-bottom: 16px;
}
/deep/ .van-tabs--line .van-tabs__wrap {
  width: 100%;
  height: 56px;
  background: #ffffff;
  box-shadow: 0px 1px 0px 0px #ededed;
  border-radius: 0px 0px 0px 0px;
  opacity: 1;
  margin-bottom: 16px;
}
/deep/ .van-tabs__line {
  background-color: #1869ff;
}
.card-item {
  width: 100%;
  background: #ffffff;
  border-radius: 0px 0px 0px 0px;
  opacity: 1;
  padding: 16px;

  .task {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    .task-name {
      width: 72.3%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      height: 22px;
      font-size: 16px;
      font-family: Source Han Sans CN-Medium, Source Han Sans CN;
      font-weight: 500;
      color: #1d2129;
      line-height: 22px;
    }
    .task-button {
      height: 24px;
      border-radius: 16px 16px 16px 16px;
      opacity: 1;
      line-height: 22px;
      font-size: 12px;
      font-family: Source Han Sans CN-Regular, Source Han Sans CN;
      font-weight: 400;
      text-align: center;
      padding: 0 8px;
    }
    .task-button-red {
      background: #fdebeb;
      border: 1px solid #f53f3f;
      color: #f53f3f;
    }
    .task-button-blue {
      border: 1px solid #1869ff;
      background: #e7efff;
      color: #1869ff;
    }
  }
  .task2 {
    display: flex;
    justify-content: space-between;
    // margin-bottom: 10px;
    .task-create {
      font-size: 14px;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #86909c;
      width: 50%;
      display: flex;
      .task-create-name {
        color: #1869ff;
        max-width: 80%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .block {
      font-size: 24px;
      font-family: Source Han Sans CN-Medium, Source Han Sans CN;
      font-weight: 500;
      color: #f53f3f;
      line-height: 20px;
    }
    .colon {
      margin: 0 2px;
    }
  }
  .task-time {
    font-size: 14px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 400;
    color: #86909c;
    // line-height: 24px;
    margin-top: 10px;
  }
  .guide {
    width: 100%;
    font-size: 15px;
    font-family: Source Han Sans CN-Regular, Source Han Sans CN;
    font-weight: 400;
    color: #4e5969;
    line-height: 24px;
    margin-bottom: 16px;
  }

  .model-type {
    .type-top {
      display: flex;
      justify-content: space-between;
      font-size: 14px;
      font-family: Source Han Sans CN-Regular, Source Han Sans CN;
      font-weight: 400;
      line-height: 14px;
      margin-bottom: 10px;
      span:nth-child(1) {
        color: #86909c;
      }
      span:nth-child(2) {
        color: #1869ff;
      }
    }
    .type-tag {
      display: flex;
      flex-wrap: wrap;
      .type-tag-item {
        background: #f2f3f5;
        border-radius: 16px 16px 16px 16px;
        padding: 0 12px;
        line-height: 32px;
        text-align: center;
        font-size: 12px;
        font-family: Source Han Sans CN-Regular, Source Han Sans CN;
        font-weight: 400;
        color: #4e5969;
        margin-right: 8px;
        margin-bottom: 8px;
      }
    }
    .all-curstom {
      font-size: 14px;
      color: #1869ff;
    }
  }
}
</style>
